package com.sz.app.customer.api.base;

import com.sz.biz.common.constants.LanguageCode;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.base.exception.BizException;
import com.sz.common.core.service.PrincipalUtils;
import com.sz.common.core.system.entity.SysDict;
import com.sz.common.core.system.service.SysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Function: ServiceTypeController <br>
 * Author: wentao.chang <br>
 * Date: 2016-11-28 14:20:00
 */
@Controller
@RequestMapping("${api}/biz/servicetypes")
@Api(description = " ", tags = "020、服务类型：供应商、服务公用")
public class ServiceTypeController {

    @Autowired
    private SysDictService dictService;

   /* @ApiOperation(value = "新建服务类型", notes = "")
    @ApiImplicitParams({@ApiImplicitParam(name = "ServiceType", value = "提交的服务类型信息\r\n "
            + "name", required = true, dataType = "ServiceType", paramType = "body")})
    @RequestMapping(value = "", method = RequestMethod.POST)
    public
    @ResponseBody
    ResultDto saveSupplier(@RequestBody ServiceType ServiceType) {
        int sid = serviceTypeService.saveServiceType(ServiceType);
        PrincipalLogUtils.addOperationLog(ModuleNames.BIZ, ModuleNames.BIZ_SERVICE_TYPE, UserActions.ADD,
                "新增服务类型：(id)" + sid);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(sid);
        return resultDto;
    }

    @ApiOperation(value = "修改服务类型", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "修改服务类型的id ", required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "ServiceType", value = "修改的服务类型信息\r\n "
                    + "name", required = true, dataType = "ServiceType", paramType = "body")})
    @RequestMapping(value = "/{sid}", method = RequestMethod.PUT)
    public
    @ResponseBody
    ResultDto updateSupplier(@PathVariable int sid, @RequestBody ServiceType ServiceType) {
        serviceTypeService.updateServiceType(sid, ServiceType);
        PrincipalLogUtils.addOperationLog(ModuleNames.BIZ, ModuleNames.BIZ_SERVICE_TYPE, UserActions.UPDATE,
                "修改服务类型：(id)" + sid);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(sid);
        return resultDto;
    }

    @ApiOperation(value = "按id获取一个服务类型", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "服务类型的id ", required = true, dataType = "int", paramType = "path")})
    @RequestMapping(value = "/{sid}", method = RequestMethod.GET)
    public
    @ResponseBody
    ResultDto findSupplierById(@PathVariable int sid) {
        ServiceType type = serviceTypeService.findServiceTypeById(sid);
        ResultDto resultDto = new ResultDto();
        resultDto.setData(type);
        return resultDto;
    }*/

    @ApiOperation(value = "获取服务类型列表", notes = "返回服务类型列表")
    @RequestMapping(value = "", method = {RequestMethod.GET})
    public
    @ResponseBody
    ResultDto getUsers() throws BizException {
        List<SysDict> dictList = dictService.findByCatalog("biz.service.type");
        SysDict tp = new SysDict();
        tp.setId(-1);
        if (LanguageCode.ZH_CN.equals(PrincipalUtils.getLocalLanguage().toLowerCase()) ||
                LanguageCode.ZH_TW.equals(PrincipalUtils.getLocalLanguage().toLowerCase()) ||
                LanguageCode.ZH_HK.equals(PrincipalUtils.getLocalLanguage().toLowerCase())) {
            tp.setName("全部");
        } else {
            tp.setName("All");
        }
        tp.setCode("-1");
        dictList.add(0, tp);

        ResultDto dto = new ResultDto();
        dto.setData(dictList);
        return dto;
    }

    /*@ApiOperation(value = "删除服务类型", notes = "非物理删除 打标志 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务类型的id", required = true, dataType = "string", paramType = "path")})
    @RequestMapping(value = "/{id}", method = {RequestMethod.DELETE})
    public
    @ResponseBody
    ResultDto deleteSupplier(@PathVariable int id) throws Exception {
        serviceTypeService.deleteServiceTypeById(id);
        PrincipalLogUtils.addOperationLog(ModuleNames.BIZ, ModuleNames.BIZ_SERVICE_TYPE, UserActions.DELETE,
                "删除服务类型：(id)" + id);
        ResultDto dto = new ResultDto();
        dto.setData(id);
        return dto;
    }*/
}
